home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
aminet
/
gfx
/
misc
/
cutitout.lha
/
cutitoutwin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-04
|
11KB
|
407 lines
/*
* Source machine generated by GadToolsBox V1.4
* which is (c) Copyright 1991,92 Jaba Development
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <string.h>
#include "cutitoutwin.h"
extern int bitgood;
struct Screen *Scr = NULL;
UBYTE *PubScreenName = NULL;
APTR VisualInfo = NULL;
struct Window *CutBitmapWnd = NULL;
struct Gadget *CutBitmapGList = NULL;
struct IntuiMessage CutBitmapMsg;
struct Gadget *CutBitmapGadgets[5];
UWORD CutBitmapLeft = 69;
UWORD CutBitmapTop = 25;
UWORD CutBitmapWidth = 518;
UWORD CutBitmapHeight = 169;
UBYTE *CutBitmapWdt = (UBYTE *)"Cut-it-out! ©1992 K.Peeters";
struct TextAttr *Font, Attr;
UWORD FontX, FontY;
UWORD OffX, OffY;
UWORD CutBitmapGTypes[] = {
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND
};
struct NewGadget CutBitmapNGad[] = {
10, 151, 83, 13, (UBYTE *)"_Load", NULL, GD_load, PLACETEXT_IN, NULL, (APTR)loadClicked
109, 151, 83, 13, (UBYTE *)"_Save", NULL, GD_save, PLACETEXT_IN, NULL, (APTR)saveClicked,
208, 151, 83, 13, (UBYTE *)"_Viewer", NULL, GD_view, PLACETEXT_IN, NULL, (APTR)viewClicked,
307, 151, 83, 13, (UBYTE *)"E_xpand", NULL, GD_expand, PLACETEXT_IN, NULL, (APTR)expandClicked,
408, 151, 83, 13, (UBYTE *)"Show _full", NULL, GD_showfull, PLACETEXT_IN, NULL, (APTR)showfullClicked,
};
ULONG CutBitmapGTags[] = {
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE)
};
static UWORD ComputeX( UWORD value )
{
return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
}
static UWORD ComputeY( UWORD value )
{
return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
}
static void ComputeFont( UWORD width, UWORD height )
{
Font = &Attr;
Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
FontX = Scr->RastPort.Font->tf_XSize;
OffX = Scr->WBorLeft;
OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
if ( width && height ) {
if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
goto UseTopaz;
if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
goto UseTopaz;
}
return;
UseTopaz:
Font->ta_Name = (STRPTR)"topaz.font";
FontX = FontY = Font->ta_YSize = 8;
}
int SetupScreen( void )
{
if ( ! ( Scr = LockPubScreen( PubScreenName )))
return( 1L );
ComputeFont( 0, 0 );
if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
return( 2L );
return( 0L );
}
void CloseDownScreen( void )
{
if ( VisualInfo ) {
FreeVisualInfo( VisualInfo );
VisualInfo = NULL;
}
if ( Scr ) {
UnlockPubScreen( NULL, Scr );
Scr = NULL;
}
}
void CutBitmapRender( void )
{
ComputeFont( CutBitmapWidth, CutBitmapHeight );
DrawBevelBox( CutBitmapWnd->RPort, OffX + ComputeX( 10 ),
OffY + ComputeY( 5 ),
ComputeX(CutBitmapWidth-20) - 2*OffX - 3,
ComputeY(CutBitmapHeight-10) - 2*OffY ,
GT_VisualInfo, VisualInfo, /* GTBB_Recessed, TRUE, */ TAG_DONE );
}
clearwin()
{
SetDrMd(CutBitmapWnd->RPort,JAM1);
SetAPen(CutBitmapWnd->RPort,0L);
RectFill(CutBitmapWnd->RPort,CutBitmapWnd->BorderLeft,
CutBitmapWnd->BorderTop,
CutBitmapWnd->Width-CutBitmapWnd->BorderRight-1,
CutBitmapWnd->Height-CutBitmapWnd->BorderBottom-1);
}
int HandleCutBitmapIDCMP( void )
{
struct IntuiMessage *m;
struct MenuItem *n;
static struct EasyStruct es =
{ sizeof(struct EasyStruct),
0,
"Information",
"Sorry, you'll have to\nmark an area first.",
"Ok"
};
struct Gadget *g;
int (*func)();
BOOL running = TRUE;
BOOL zooming = FALSE;
BOOL marked = FALSE;
BOOL inframe = FALSE;
int x,y,zoomx[2],zoomy[2];
do
{ Wait(1<<CutBitmapWnd->UserPort->mp_SigBit);
while( m = GT_GetIMsg( CutBitmapWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&CutBitmapMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( CutBitmapMsg.Class ) {
case IDCMP_MOUSEMOVE:
x=m->MouseX;
y=m->MouseY;
entrytwo:
SetAPen(CutBitmapWnd->RPort,1L);
SetDrMd(CutBitmapWnd->RPort,COMPLEMENT);
if(!marked)
{ if(x>leftbevinwin() && x<rightbevinwin() &&
y>=topbevinwin() && y<bottombevinwin() )
{ if(!inframe)
{ if(!zooming) drawcross(FALSE,TRUE,x,y);
else drawrubber(FALSE,TRUE,x,y,zoomx,zoomy);
}
else
{ if(!zooming) drawcross(TRUE,TRUE,x,y);
else drawrubber(TRUE,TRUE,x,y,zoomx,zoomy);
}
inframe=TRUE;
}
else
{ if(inframe)
{ if(!zooming) drawcross(TRUE,FALSE,x,y);
else drawrubber(TRUE,FALSE,x,y,zoomx,zoomy);
}
inframe=FALSE;
}
}
SetAPen(CutBitmapWnd->RPort,1L);
SetDrMd(CutBitmapWnd->RPort,JAM1);
break;
case IDCMP_MOUSEBUTTONS:
if(CutBitmapMsg.Code==SELECTUP)
{ x=m->MouseX;
y=m->MouseY;
SetAPen(CutBitmapWnd->RPort,1L);
SetDrMd(CutBitmapWnd->RPort,COMPLEMENT);
if(marked)
{ drawrubber(TRUE,FALSE,x,y,zoomx,zoomy);
marked=FALSE;
inframe=FALSE;
goto entrytwo;
}
if(!zooming)
{ if(x>leftbevinwin() && x<rightbevinwin() &&
y>topbevinwin() && y<bottombevinwin() )
{ zooming=TRUE;
zoomx[0]=x;
zoomy[0]=y;
drawcross(TRUE,FALSE,x,y);
drawrubber(FALSE,TRUE,x,y,zoomx,zoomy);
}
}
else
{ if(x>leftbevinwin() && x<rightbevinwin() &&
y>topbevinwin() && y<bottombevinwin() )
{ zooming=FALSE;
marked=TRUE;
zoomx[1]=x;
zoomy[1]=y;
drawrubber(TRUE,TRUE,x,y,zoomx,zoomy);
}
else { zooming=FALSE;
marked=FALSE;
drawrubber(TRUE,FALSE,x,y,zoomx,zoomy);
drawcross(FALSE,TRUE,x,y);
}
}
SetAPen(CutBitmapWnd->RPort,1L);
SetDrMd(CutBitmapWnd->RPort,JAM1);
}
break;
case IDCMP_NEWSIZE:
zooming=FALSE;
marked=FALSE;
inframe=FALSE;
CutBitmapWidth=CutBitmapWnd->Width-OffX-Scr->WBorRight;
CutBitmapHeight=CutBitmapWnd->Height-OffY-Scr->WBorBottom;
clearwin();
SetAPen(CutBitmapWnd->RPort,1L);
CutBitmapRender();
RemoveGList(CutBitmapWnd,CutBitmapGList,-1);
FreeGadgets(CutBitmapGList);
CutBitmapGList=NULL;
g=NULL;
if(addgadgets(g)!=0) { running=FALSE; break; }
AddGList(CutBitmapWnd,CutBitmapGList,~0,-1,NULL);
RefreshGList(CutBitmapGList,CutBitmapWnd,NULL,-1);
GT_BeginRefresh( CutBitmapWnd );
GT_EndRefresh( CutBitmapWnd, TRUE );
refreshit();
break;
case IDCMP_REFRESHWINDOW:
zooming=FALSE;
GT_BeginRefresh( CutBitmapWnd );
CutBitmapRender();
GT_EndRefresh( CutBitmapWnd, TRUE );
break;
case IDCMP_CLOSEWINDOW:
zooming=FALSE;
CloseCutBitmapWindow();
running=FALSE;
return(FALSE);
break;
case IDCMP_GADGETUP:
case IDCMP_GADGETDOWN:
zooming=FALSE;
inframe=FALSE;
func = ( void * )(( struct Gadget * )CutBitmapMsg.IAddress )->UserData;
if(func==(void *)saveClicked)
{ if(marked && bitgood)
{ SetDrMd(CutBitmapWnd->RPort,COMPLEMENT);
drawrubber(TRUE,FALSE,zoomx[1],zoomy[1],zoomx,zoomy);
flip(zoomx);
flip(zoomy);
saveClicked(zoomx,zoomy);
drawrubber(FALSE,TRUE,zoomx[1],zoomy[1],zoomx,zoomy);
SetDrMd(CutBitmapWnd->RPort,JAM1);
}
else EasyRequest(CutBitmapWnd,&es,NULL,NULL);
}
else { running = func();
marked=FALSE;
}
break;
}
}
} while(running);
}
flip(ar)
int *ar;
{
int fl;
if(ar[0]>ar[1])
{ fl=ar[0];
ar[0]=ar[1];
ar[1]=fl;
}
}
int OpenCutBitmapWindow( void )
{
int result;
struct Gadget *g;
UWORD wleft = CutBitmapLeft, wtop = CutBitmapTop, ww, wh;
ComputeFont( CutBitmapWidth, CutBitmapHeight );
ww = ComputeX( CutBitmapWidth );
wh = ComputeY( CutBitmapHeight );
if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
if((result=addgadgets(g))!=0) return(result);
if ( ! ( CutBitmapWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + OffX + Scr->WBorRight,
WA_Height, wh + OffY + Scr->WBorBottom,
WA_IDCMP, BUTTONIDCMP|IDCMP_NEWSIZE|IDCMP_GADGETDOWN|IDCMP_MOUSEMOVE|IDCMP_MOUSEBUTTONS|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_REPORTMOUSE,
WA_Gadgets, CutBitmapGList,
WA_Title, CutBitmapWdt,
WA_ScreenTitle, "Cut-it-out!",
WA_PubScreen, Scr,
WA_MinWidth, 5*ComputeX(95)+10,
WA_MinHeight, 80,
WA_MaxWidth, 688,
WA_MaxHeight, 264,
TAG_DONE )))
return( 4L );
GT_RefreshWindow( CutBitmapWnd, NULL );
CutBitmapRender();
return( 0L );
}
addgadgets(g)
struct Gadget *g;
{
struct NewGadget ng;
UWORD lc,tc;
if ( ! ( g = CreateContext( &CutBitmapGList )))
return( 1L );
for( lc = 0, tc = 0; lc < CutBitmap_CNT; lc++ )
{ CopyMem((char * )&CutBitmapNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_TopEdge = CutBitmapHeight-18;
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = Font;
ng.ng_LeftEdge = OffX+ComputeX(10+4) + 1 + lc*((bevelwidth()-ComputeX(ng.ng_Width))/4);
ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
ng.ng_Width = ComputeX( ng.ng_Width );
ng.ng_Height = ComputeY( ng.ng_Height);
CutBitmapGadgets[ lc ] = g = CreateGadgetA((ULONG)CutBitmapGTypes[ lc ], g, &ng, ( struct TagItem * )&CutBitmapGTags[ tc ] );
while( CutBitmapGTags[ tc ] ) tc += 2;
tc++;
if ( NOT g )
return( 2L );
}
return(0);
}
void CloseCutBitmapWindow( void )
{
if ( CutBitmapWnd ) {
CloseWindow( CutBitmapWnd );
CutBitmapWnd = NULL;
}
if ( CutBitmapGList ) {
FreeGadgets( CutBitmapGList );
CutBitmapGList = NULL;
}
}